package com.yesun.dcm.rpc.protocol;

import com.yesun.dcm.commons.rpc.URL;
import com.yesun.dcm.rpc.Invoker;
import com.yesun.dcm.rpc.RpcRequest;
import com.yesun.dcm.rpc.RpcResponse;

/**
 * 远程调用抽象类
 * @param <T>
 */
public abstract class AbstractInvoker<T> implements Invoker<T> {

    protected URL url;
    private Class<T> clazz;

    public AbstractInvoker(Class<T> clazz, URL url) {
        this.clazz = clazz;
        this.url = url;
    }

    @Override
    public URL getURL() {
        return url;
    }

    @Override
    public Class<T> getInterface() {
        return clazz;
    }

    @Override
    public RpcResponse invoke(RpcRequest request) {
        return doInvoke(request);
    }

    /**
     * 远程调用抽象方法
     * @param request
     * @return
     */
    protected abstract RpcResponse doInvoke(RpcRequest request);
}
